/**
 * 633. 平方数之和
 * 给定一个非负整数 c，判断是否存在两个整数 a 和 b，使得 a^2 + b^2 = c
 * @link https://leetcode-cn.com/problems/sum-of-square-numbers/
 *
 * @param {number} c
 * @return {boolean}
 */
var judgeSquareSum = function (c) {
    let l = 0;
    let r = Math.floor(Math.sqrt(c));
    while (l <= r) {
        const actual = l * l + r * r;
        if (actual === c) return true;
        if (actual < c) l = l + 1;
        else r = r - 1;
    }

    return false;
};
